package com.example.design.generic.test03;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Description 泛型类
 * @date 2022/9/19 9:18
 * @Author liuzhihui
 * @Version 1.0
 */
public class DAO<T>{
    Map<String,T> map;

    public DAO(Map<String, T> map) {
        this.map = map;
    }

    public Map<String, T> getMap() {
        return map;
    }

    public void save(String id, T entity) {
        map.put(id, entity);
    }

    public T get(String id) {
        return map.get(id);
    }

    public void update(String id, T entity) {
        map.put(id, entity);
    }

    public List<T> list() {
        return new ArrayList<>(map.values());
    }

    public void delete (String id) {
        map.remove(id);
    }
}
